function plusReady(callback) {
  if (window.plus) {
    callback();
  } else {
    document.addEventListener('plusready', callback);
  }
}

plusReady(() => {
  let Bridge = window.plus.bridge;

  window.plus.hatom = {
    //实时预览
    preview(url, title) {
      let callbackID = Bridge.callbackId(null, null);
      return Bridge.exec("HatomVideoPlayerPlugin",
        "startHatom", [callbackID, {
          "requestCode": 3001,
          "url": url,
          "title": title || "实时预览"
        }]);
    },
    previewRetry(params) {
      let callbackID = Bridge.callbackId(null, null);
      return Bridge.exec("HatomVideoPlayerPlugin",
            "startHatomRe", [callbackID,
              {
                ...{
                    baseUrl: "http://qjt.championsoft.net/openapi/video/hkisc/previewurls",
                    serverIp: "58.48.64.198",
                    port: "1443",
                    appKey: "24173294",
                    appSecret: "mKGlY1LJIGruJ0hq1uA3",
                    requestCode: 3001,
                  },
                ...params
      }]);
    },
    // //预留回放，暂无需求未实现
    // playback(url) {
    //   let callbackID = Bridge.callbackId(null, null);
    //   return Bridge.exec("HatomVideoPlayerPlugin",
    //           "startHatom", [callbackID, {
    //             "requestCode": 3003,
    //             "url": url}]);
    // },
  }

  window.plus.aiFace = {
    getUserFaces(params, successCallback, errorCallback) {
      let success = typeof successCallback !== 'function' ? null : function (args) {
        successCallback(args);
      };
      let fail = typeof errorCallback !== 'function' ? null : function (code) {
        errorCallback(code);
      };
      let callbackID = Bridge.callbackId(success, fail);

      return Bridge.exec("AiFace", "getUserFaces", [callbackID, params]);
    },
    deleteUserFaces(params, successCallback, errorCallback) {
      let success = typeof successCallback !== 'function' ? null : function (args) {
        successCallback(args);
      };
      let fail = typeof errorCallback !== 'function' ? null : function (code) {
        errorCallback(code);
      };
      let callbackID = Bridge.callbackId(success, fail);

      return Bridge.exec("AiFace", "deleteUserFaces", [callbackID, params]);
    },
    detect(params, successCallback, errorCallback) {
      let success = typeof successCallback !== 'function' ? null : function (args) {
        successCallback(args);
      };
      let fail = typeof errorCallback !== 'function' ? null : function (code) {
        errorCallback(code);
      };
      let callbackID = Bridge.callbackId(success, fail);

      return Bridge.exec("AiFace", "Detect", [callbackID, params]);
    },
    liveCheck(params, successCallback, errorCallback) {
      let success = typeof successCallback !== 'function' ? null : function (args) {
        successCallback(args);
      };
      let fail = typeof errorCallback !== 'function' ? null : function (code) {
        errorCallback(code);
      };
      let callbackID = Bridge.callbackId(success, fail);

      return Bridge.exec("AiFace", "LiveCheck", [callbackID, params]);
    }
  };

  window.plus.aiOcr = {
    init(successCallback, errorCallback) {
      let success = typeof successCallback !== 'function' ? null : function (args) {
        successCallback(args);
      };
      let fail = typeof errorCallback !== 'function' ? null : function (code) {
        errorCallback(code);
      };
      let callbackID = Bridge.callbackId(success, fail);

      return Bridge.exec("AiOcr", "Init", [callbackID]);
    },
    scanIDCard(isFont, successCallback, errorCallback) {
      let success = typeof successCallback !== 'function' ? null : function (args) {
        successCallback(args);
      };
      let fail = typeof errorCallback !== 'function' ? null : function (code) {
        errorCallback(code);
      };
      let callbackID = Bridge.callbackId(success, fail);

      return Bridge.exec("AiOcr", "ScanIDCard", [callbackID], isFont);
    }
  };

  window.plus.util = {
    isEnabledGPS() {
      if (window.plus.os.name == "Android") {
        var context = window.plus.android.importClass("android.content.Context");
        var locationManager = window.plus.android.importClass("android.location.LocationManager");
        var main = window.plus.android.runtimeMainActivity();
        var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
        return mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER);
      } else if (window.plus.os.name == "iOS") {
        var result = false;
        var CLLocationManager = window.plus.ios.import("CLLocationManager");
        var authorizationStatus = CLLocationManager.authorizationStatus();
        switch (authorizationStatus) {
          case 0:
            //用户尚未对此应用程序做出选择
          case 1:
            //此应用程序无权使用位置服务
          case 2:
            //用户已明确拒绝对此应用程序的授权，或者位置服务在设置中被禁用
            result = false;
            break;
          case 3:
            //用户已授权随时使用其位置
          case 4:
            //用户已授权仅在他们使用APP的时候使用其位置
          case 5:
            //该值无效
            result = true;
            break;
        }
        return result;
      } else {
        return false;
      }
    }
  };
});

export default {};
